Random = Mock.Random

function getPet(){
    let commentList = []

    for(let i = 0 ; i < 15; i++){
        let comment = Mock.mock({
            "id" : Random.integer(0,1000),
            "avatar": Random.image(),
            "comment": Random.cparagraph(),
            "username" : Random.cname(),
            "date" : Random.datetime()
        })

        commentList.push(comment)
    }


    let data = Mock.mock({
        "name" : Random.cname(),
        "type" : Random.cname(),
        "kind" : Random.cname(),
        "intro" : Random.cparagraph(10),
        "price" : Random.float(500,1000,2,2),
        "image" : Random.image(),
        "stock" : Random.integer(0,1000),
        "added" : Random.integer(0,1),
        "commentList" : commentList
    })

    let json = {
        code : 200,
        msg : "获取成功",
        data: data,
    }

    return json
}

function changePet(){
    return {
        code : 200,
        msg: '修改成功'
    }
}

function delComment(){
    return {
        code : 200,
        msg: '删除成功'
    }
}

function uploadRes(){
    let json = Mock.mock({
        code : 200,
        data : Random.image(),
        msg: '上传成功'
    })

    return json
}

Mock.mock(/http:\/\/localhost\/get_pet.php.*?/, 'get', getPet())

Mock.mock('http://localhost/change_pet.php', 'post', changePet())

Mock.mock('http://localhost/change_pet_avatar.php', 'post', changePet)

Mock.mock('http://localhost/upload.php', 'post', uploadRes)

Mock.mock('http://localhost/del_comment.php', 'post', delComment)